<?php

class transaction_type{
	
	// Define variables
	private $ID_TRANSACTION_TYPE;
	private $TT_NAME;
	
	// Connection with database and instance creation
	private $DB;
	public function __construct() {
		$config = config::getInstance();
		$this->DB = $config->config_values['database']['db_prefix'];
	}
	
	// Getters and setters functions
  	public function setID_TRANSACTION_TYPE($value) {
  		$this->ID_TRANSACTION_TYPE = $value;
  	}
	public function getID_TRANSACTION_TYPE() {
  		return $this->ID_TRANSACTION_TYPE;
  	}
	public function setTT_NAME($value) {
  		$this->TT_NAME = $value;
  	}
	public function getTT_NAME() {
  		return $this->TT_NAME;
  	}

	// General functions:
  	public function load($id)
	{
		$db = db::getInstance();
		$sql = "SELECT * FROM ".$this->DB."transaction_type WHERE ID_TRANSACTION_TYPE=".$id;

		foreach ($db->query($sql) as $row) {
			$this->setID_TRANSACTION_TYPE($row['ID_TRANSACTION_TYPE']);
			$this->setTT_NAME($row['TT_NAME']);
		}
	    $db = null; 
	    return true;			
  	}

  	public function insert(){}

  	public function modify($id){}

  	public function delete($id){}
  	
  	// JSON function:
	public function jsonList(){
		try {
    		$db = db::getInstance();
			$sql = "SELECT * FROM ".$this->DB."transaction_type";
			$sth=$db->prepare($sql);
			$sth->execute();
			$recordset = array();
			$recordset = $sth->fetchAll(PDO::FETCH_ASSOC);
			return $recordset;			
		} catch (Exception $e) {
  			return false;
		}		
	}
}
?>